<?php
namespace Model;
use DB;

class User extends \Model {

    public static function is_valid($username, $password) {
		$query = DB::select('role')->from('users');
		$query->where('username', '=', $username);	
		$query->and_where('password', '=', md5($password));	
		$query->and_where('role', '!=', 0);
		$r = $query->execute();
		if (count($r->as_array()) > 0) return true;
		return false;
    }

    public static function get_role($username, $password) {
		$query = DB::select('role')->from('users');
		$query->where('username', '=', $username);	
		$query->and_where('password', '=', md5($password));	
		$query->and_where('role', '!=', 0);
		$r = $query->execute();
		return $r[0]['role'];
    }
    public static function get_id($username, $password) {
		$query = DB::select('id')->from('users');
		$query->where('username', '=', $username);	
		$query->and_where('password', '=', md5($password));	
		$query->and_where('role', '!=', 0);
		$r = $query->execute();
		return $r[0]['id'];
    }

}
